<?php
/**
 * Framework Pluggable Functions.
 *
 * These functions can be replaced via styles/plugins. If styles/plugins do
 * not redefine these functions, then these will be used instead.
 *
 * @package WP_Framework
 */


/**
 * framework_entry_author() - Displays the current post author.
 * Formatted for hAtom microformat.
 *
 * @since 0.3
 */
if ( ! function_exists( 'framework_entry_author' ) ):
	function framework_entry_author( $args = array() ) {
		$defaults = array( 'author' => true, 'before' => 'by ', 'after' => '. ' );
		$r = wp_parse_args( $args, $defaults );
		$output = "";
		if( $r[ 'author' ] ){
			$output .= "\n". '<span class="entry-author">' . "\n";
			$output .= $r['before'] . '<span class="vcard author"><a href="';
			$output .= get_author_posts_url( get_the_author_ID() );
			$output .= '" class="url fn" title="';
			$output .= sprintf( 'View all posts by %s', attribute_escape( get_the_author() ) );
			$output .= '">';
			$output .= get_the_author();
			$output .= '</a></span>' . $r[ 'after' ] . "\n";
			$output .= "</span>\n";
		}
		
		return $output;
	}
endif;

/**
 * framework_entry_date() - Displays the current post date, if time since is installed, it will use that instead.
 * Formatted for hAtom microformat.
 *
 * @since 0.3
 */
if ( ! function_exists('framework_entry_date') ):
	function framework_entry_date( $args = array() ) {
		global $post;
		$defaults = array( 'date' => true, 'before' => 'Published in ', 'after' => NULL );
		$r = wp_parse_args( $args, $defaults );
		$output = '';
		if ( $r[ 'date' ] ) {
			$output .= "\n" .'<span class="entry-date">'. "\n";
			$output .= $r[ 'before' ];
			$output .= '<abbr class="published" title="' . get_the_time('Y-m-d\TH:i:sO') . '">';
			$output .= get_the_time( get_option('date_format') );
			$output .= '</abbr>';
			$output .= $r[ 'after' ] . "\n" .'</span>'. "\n";
		}
		return $output;
	}
endif;

/**
 * framework_entry_categories() - Displays the current post categories
 *
 * @since 0.3
 * @uses framework_nice_category
 */
if ( ! function_exists('framework_entry_categories') ):
	function framework_entry_categories( $args = array() ) {				
		$defaults = array( 'cats' => true, 'single' => 'This entry was posted in', 'archive' => 'Also posted in', 'default' => 'Posted in',
					   'meta_sep_single' => false, 'meta_sep_archive' => false, 'meta_sep_default' => false );

		$r = wp_parse_args( $args, $defaults );
		$cats_meow = framework_get_terms( 'cats' );
		if ( $cats_meow and $r[ 'cats' ] ) {
			$cats = "\n<span class=\"entry-categories\">\n";
			if ( is_single() ) {
				if ( $r[ 'meta_sep_single' ] ) {
						$cats .= '<span class="meta-sep">'. $r[ 'meta_sep_single' ] .'</span>';
				}
				$cats .= $r[ 'single' ] . ' <span class="entry-cats-links">';
				$cats .= framework_nice_terms( 'cats', ', ', ' and ', '. ' );
			}
			elseif ( is_category() ) {
				if ( $r[ 'meta_sep_archive' ] ) {
					$cats .= '<span class="meta-sep">'. $r[ 'meta_sep_archive' ] .'</span>';
				}
				$cats .= $r[ 'archive' ] . ' <span class="entry-cats-links">' . framework_nice_terms( 'cats', ', ', ' and ', '. ' );
			}
			else {
				if ( $r[ 'meta_sep_default' ] ) {
					$cats .= '<span class="meta-sep">'. $r[ 'meta_sep_default' ] .'</span>';
				}
				$cats .= $r[ 'default' ] . ' <span class="entry-cats-links">';
				$cats .= framework_nice_terms( 'cats', ', ', ' and ', '. ' );
			}
			$cats .= "</span>\n</span>\n";
		}
		if ( $cats_meow and $r[ 'cats' ] ) return $cats;
	}
endif;

/**
 * framework_entry_tags() - Displays the current post tags or blank if none.
 *
 * @since 0.3
 */
if ( ! function_exists('framework_entry_tags') ):
function framework_entry_tags( $args = array() ) {
	$defaults = array( 'tags' => true, 'single' => ' and tagged', 'archive' => 'Also tagged', 'default' => 'Tagged',
					   'meta_sep_single' => false, 'meta_sep_archive' => false, 'meta_sep_default' => false );
					   
	$r = wp_parse_args( $args, $defaults );
	$tag_ur_it = framework_get_terms( 'tags' );

	if ( $tag_ur_it and $r[ 'tags' ] ) {
		$tags = "\n<span class=\"entry-tags\">\n";
		if ( is_single() ) {
			if ( $r[ 'meta_sep_single' ] and framework_get_terms( 'cats' ) ) {
					$tags .= '<span class="meta-sep">'. $r[ 'meta_sep_single' ] .'</span>';
			}
			$tags .= $r[ 'single' ] . ' <span class="entry-tags-links">';
			$tags .= framework_nice_terms( 'tags', ', ', ' and ', '. ' );
		}
		elseif ( is_tag() ) {
			if ( $r[ 'meta_sep_archive' ] and framework_get_terms( 'cats' ) ) {
				$tags .= '<span class="meta-sep">'. $r[ 'meta_sep_archive' ] .'</span>';
			}
			$tags .= $r[ 'archive' ] . ' <span class="entry-tags-links">' . framework_nice_terms( 'tags', ', ', ' and ', '. ' );
		}
		elseif ( get_the_tag_list( ' ', ', ', ' ' ) ) {
			if ( $r[ 'meta_sep_default' ] and framework_get_terms( 'cats' ) ) {
				$tags .= '<span class="meta-sep">'. $r[ 'meta_sep_default' ] .'</span>';
			}
			$tags .= $r[ 'default' ] . ' <span class="entry-tags-links">';
			$tags .= framework_nice_terms( 'tags', ', ', ' and ', '. ' );
		}
		$tags .= "</span>\n</span>\n";
	}
	if ( $tag_ur_it and $r[ 'tags' ] ) return $tags;
}
endif;

/**
 * framework_entry_edit - Entry Edit link
 *
 * @since 0.3
 */
if ( ! function_exists('framework_entry_edit') ):
function framework_entry_edit() {
	global $post;

	if ( $post->post_type == 'page' ) {
		if ( !current_user_can( 'edit_page', $post->ID ) )
			return;
	} else {
		if ( !current_user_can( 'edit_post', $post->ID ) )
			return;
	}
	$link = '<a class="entry-edit-link" href="' . get_edit_post_link( $post->ID ) . '" title="' . attribute_escape( 'Edit post' ) . '">edit</a>';
	$edit = '<span class="entry-edit">' . apply_filters( 'edit_post_link', $link, $post->ID ) . '</span>';
	return $edit;
}
endif;

/**
 * framework_entry_comments() - Displays the number of comments in current post enclosed in a link.
 *
 * @since 0.3
 */
if ( ! function_exists('framework_entry_comments') ):
	function framework_entry_comments() {
		if (is_singular()) return;
		ob_start();

		comments_popup_link( 'leave a comment', '<span class="comment-count">1</span> comment', '<span class="comment-count">%</span> comments', 'commentslink', '<span class="comments-closed">comments closed</span>' );

		return '<span class="entry-comments">' . ob_get_clean() . '</span>';
	}
endif;

/**
 * framework_entry_time() - Displays the current post time
 *
 * @since 0.3
 */
if ( ! function_exists('framework_entry_time') ):
	function framework_entry_time() {
		return '<span class="entry-time">' . get_the_time( get_option('time_format') ) . '</span>';
	}
endif;

/**
 * register_widgets() - Register Widgets
 *
 * @since - 0.3
 * @todo - work on widgets in 0.4
 */
if ( ! function_exists( 'register_widgets' ) ):
	function register_widgets() {
		register_sidebars( REGISTER_WIDGETS, array(
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget' 	=> '</div>',
			'before_title' 	=> '<h3 class="widget-title">',
			'after_title' 	=> '</h3>',
		));
	}
endif;
?>